﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jzy.Core.Common;
using FortuneHeavenCommon.DataMap;

namespace FortuneHeavenDAL
{
    public class GiftOrderDAL : BaseDAL
    {
        public List<GiftOrder> GetGiftOrder(int page, int size,string orderID)
        {
            if (string.IsNullOrEmpty(orderID) ||orderID.Trim() =="")
            {
                string sql = @"SELECT * FROM (select A.[ID],A.[OrderID],A.[UserName],
A.[Status],A.[Time],A.[GiftID],A.[AuditID] ,ROW_NUMBER() OVER(ORDER BY A.ID DESC) ROW   
,B.Name AS GiftName,C.RealName as AuditName
from GiftOrder A  left join Gift B on A.GiftID=B.ID left join AdminUser C on A.AuditID = C.ID
 ) FF
 WHERE FF.ROW BETWEEN  @p0 AND @p1";
                List<GiftOrder> list = dbOper.Query<GiftOrder>(sql, size * (page - 1)+1, size * page);
                return list;
            }
            else
            {
                string sql = @"SELECT * FROM (select A.[ID],A.[OrderID],A.[UserName],
A.[Status],A.[Time],A.[GiftID],A.[AuditID] ,ROW_NUMBER() OVER(ORDER BY A.ID DESC) ROW   
,B.Name AS GiftName,C.RealName as AuditName,A.AddressID 
from GiftOrder A left join Gift B on A.GiftID=B.ID left join AdminUser C on A.AuditID = C.ID
WHERE A.OrderID=@p0 ) FF
 
 WHERE FF.ROW BETWEEN  @p1 AND @p2";
                List<GiftOrder> list = dbOper.Query<GiftOrder>(sql,orderID, size * (page - 1)+1, size * page);
                return list;
            }
        }
        public int GetTotalSize(string orderID)
        {
            if (!string.IsNullOrEmpty(orderID) && orderID.Trim() !="")
            {
                string sql = @"select count(id) from GiftOrder where OrderID =@p0";
                return dbOper.GetScalar<int>(sql, orderID);
            }
            else
            {
                string sql = @"select count(id) from GiftOrder";
                return dbOper.GetScalar<int>(sql);
            }
        }
        public void AuditItems(string ids,int aduitid)
        {
            string sql = "update GiftOrder set Status =1,AuditID =@p0 where ID in({0})";
            dbOper.RunSql(string.Format(sql,ids),aduitid);
        }
    }
}
